package com.dailyblue.java.project.power.service.impl;

import com.dailyblue.java.project.power.bean.JsonResult;
import com.dailyblue.java.project.power.bean.Powers;
import com.dailyblue.java.project.power.mapper.PowersMapper;
import com.dailyblue.java.project.power.service.PowersService;
import com.dailyblue.java.project.power.util.ResultTool;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PowersServiceImpl implements PowersService {
    @Resource
    private PowersMapper powersMapper;

    public JsonResult<List<Powers>> findAllPower() {
        return ResultTool.success(powersMapper.findAllPower());
    }

    @Override
    public JsonResult<List<Powers>> findPowerByUserId(int uid) {
        // 所有的权限
        List<Powers> list = powersMapper.findAllPower();
        // 查询用户的权限
        List<Powers> your = powersMapper.findPowerByUserId(uid);
        for (Powers p : list) {
            boolean b = your.contains(p);
            p.setChoose(b);
        }
        return ResultTool.success(list);
    }
}
